package edu.ccit.shudong.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import edu.ccit.shudong.dto.PostProfileDTO;
import edu.ccit.shudong.dto.UserProfileDTO;
import edu.ccit.shudong.entity.Message;
import edu.ccit.shudong.entity.Post;
import edu.ccit.shudong.entity.User;
import edu.ccit.shudong.mapper.PostMapper;
import edu.ccit.shudong.service.IPostService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.ccit.shudong.utils.JwtUtils;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Value;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Suting Luo
 * @since 2024-06-14
 */
@Service
public class PostServiceImpl extends ServiceImpl<PostMapper, Post> implements IPostService {

    @Value("${shudong.page.max.size}")
    private int pageMaxSize;

    @Override
    public IPage<Post> getPage(long current, long size) {
        size = size > pageMaxSize ? pageMaxSize : size;
        IPage<Post> page = new Page<>(current, size);
        return this.page(page);
    }

    @Override
    public PostProfileDTO getProfileByToken(String token) {
        long userId = JwtUtils.getUserId(token);
        List<Post> post = findListByUserId(userId);
        PostProfileDTO postProfileDTO = new PostProfileDTO();
        postProfileDTO.setUserId(userId);
        return postProfileDTO;
    }

    private List<Post> findListByUserId(long userId) {
        QueryWrapper<Object> wrapper = new QueryWrapper<>().eq("user_id",userId);
        return Collections.emptyList();
    }

}
